(function (G) {
  G.vue({
    noLogin:true,
    data:{
      logo:G.Storage.get('logo'),
      models:{
        userName:{
          type: 'input',
          label: '用户名',
          rule: { NotNull: true }
        },
        passWord:{
          label: '密码',
          type: 'input',
          attr: { type: 'password' },
          rule: { NotNull: true }
        }
      },
      submiting: false
    },
    methods:{
      submit:function(){
        var _this = this;
        var data = this.selectComponent('#loginForm').submit();
        if(!data) return false;
        data.passWord = G.MD5(data.passWord);
        data.platform = G.platform;
        this.setData({submiting:true});
        G.ajax('/login',function(ret){
          _this.setData({ submiting: false });
          if(!ret.errorMsg){
            G.Storage.set('user', ret, 1);
            var activeGroupId = G.Storage.get('groupId', 1);
            G.Storage.remove('groupId');
            var hasActive = false;
            for (var i = 0; i < ret.groups.length; i++) if (activeGroupId == ret.groups[i].groupId) hasActive = true;
            if (!hasActive && ret.groups[0]) activeGroupId = ret.groups[0].groupId;
            G.Storage.set('groupId', activeGroupId, 1);
            G.Storage.get('autoLogin')(function () {
              G.$go(G.Storage.get('loginRedirectTo') || '/pages/index/index', 'redirectTo')
            })
          }
        },{
          meth:'POST',
            data: data
        })
      }
    }
  });
})(wx.$)
